package com.jojo.bubble.controller;

import com.jojo.bubble.entity.Logs;
import com.jojo.bubble.service.LogsService;
import com.jojo.bubble.common.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.ObjectUtils;
import com.jojo.bubble.common.enums.JsonResultEnum;

import javax.annotation.Resource;
import java.util.List;

/**
 * 操作日志(Logs)表控制层
 *
 * @author jojo
 * @since 2023-08-08 13:35:20
 */
@RestController
@RequestMapping("/admin/logs")
public class LogsController {
    /**
     * 服务对象
     */
    @Resource
    private LogsService logsService;


    @GetMapping("/list")
    public AjaxResult getList(Logs record) {
        List<Logs> logsList = logsService.getList(record);
        return AjaxResult.success(logsList);
    }

    @GetMapping("/info")
    public AjaxResult getInfo(Integer id) {
        Logs logs = logsService.getInfo(id);
        return AjaxResult.success(logs);
    }

    @PostMapping("/insert")
    public AjaxResult insert(Logs record) {
        logsService.insert(record);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    public AjaxResult update(Logs record) {
        Logs logs = logsService.getInfo(record.getId());
        if (ObjectUtils.isEmpty(logs)) {
            return AjaxResult.error(JsonResultEnum.RECORD_NULL);
        }
        logsService.update(record);
        return AjaxResult.success();
    }

    @PostMapping("/delete")
    public AjaxResult delete(int id) {
        logsService.delete(id);
        return AjaxResult.success();
    }
}

